# 这个文件需要在工程根目录执行 build
FROM python:3.12.11-bookworm
# 更换Debian bookworm的apt源为阿里云镜像（国内访问更快）
RUN echo "deb http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" > /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian/ bookworm main non-free contrib" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian-security/ bookworm-security main" >> /etc/apt/sources.list && \
    echo "deb http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list && \
    echo "deb-src http://mirrors.aliyun.com/debian/ bookworm-updates main non-free contrib" >> /etc/apt/sources.list
# 安装OpenCV依赖的系统库
RUN apt-get update \
    && apt-get install -y iputils-ping \
    && apt-get install -y net-tools \
    && apt-get install -y ffmpeg libgl1-mesa-glx libglib2.0-0 libsm6 libxext6 ninja-build libxrender-dev \
    && rm -rf /var/lib/apt/lists/*
COPY . /app/
COPY ./docker/start.sh /app/
COPY ./docker/gunicorn.conf.py /app/
WORKDIR /app/
RUN pwd
ENV TIME_ZONE "Asia/Shanghai"
RUN pip install --default-timeout=1688 -i https://mirrors.aliyun.com/pypi/simple -r requirements.txt
RUN echo "${TIME_ZONE}" > /etc/timezone && ln -sf /usr/share/zoneinfo/${TIME_ZONE} /etc/localtime
RUN chmod +x /app/start.sh
ENTRYPOINT ["/bin/bash"]
# 5000 http端口 8839 tcpserver端口
EXPOSE 8838 8839 8840
CMD ["./start.sh"]

